import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-05-07
 * Time: 22:02
 */
public class Test {
    public static boolean threeConsecutiveOdds(int[] array){
        for (int i = 0; i < array.length - 2; i++) {
            if(array[i] % 2 != 0 && array[i + 1] % 2 != 0 && array[i + 2] % 2 != 0){
                return true;
            }
        }
        return false;
    }
    public static void main(String[] args) {//存在连续三个奇数的数组
        int[] array = new int[]{1,2,3,4,5,6};
        System.out.println(threeConsecutiveOdds(array));

    }
    public static int[] sum_Of_The_Two_Numbers(int[] array,int target){//两数之和
        int[] ret = new int[2];
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if(array[i] + array[j] == target){
                    ret[0] = i;
                    ret[1] = j;
                    return ret;
                }
            }
        }
        return ret;
    }
    public static void main6(String[] args) {
        Scanner sc = new Scanner(System.in);
        int target = sc.nextInt();
        int[] array = new int[]{3,2,4};
        int[] result = sum_Of_The_Two_Numbers(array,target);
        System.out.println(Arrays.toString(result));
    }
    public static int binary_Search(int[] array,int x){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(array[mid] == x){
                return mid;
            }else if(array[mid] < x){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return -1;
    }
    public static void main1(String[] args) {//二分查找
        int[] array = new int[]{1,2,3,4,5,6,7,8};
        int ret = binary_Search(array,8);
        if(ret != -1){
            System.out.println("找到了，下标为" + ret);
        }else{
            System.out.println("找不到");
        }
    }
    public static void bubbling_Sorting(int[] array){
        for (int i = 0; i < array.length - 1; i++) {
            int flag = 0;
            for (int j = 0; j < array.length - 1 - i; j++) {//每趟比较次数优化
                if(array[j] > array[j + 1]){
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                    flag = 1;
                }
            }
            if(flag == 0){//某次已经排好优化
                return;
            }
        }
    }
    public static void main4(String[] args) {//冒泡排序
        int[] array = new int[]{1,3,5,7,2,4,6,9};
        System.out.println("交换前：");
        System.out.println(Arrays.toString(array));
        System.out.println("交换后：");
        bubbling_Sorting(array);
        System.out.println(Arrays.toString(array));
    }
    public static int find_Different(int[] array){//
        int ret = 0;
        for (int i = 0; i < array.length; i++) {
            ret ^= array[i];
        }
        return ret;
    }
    public static void main3(String[] args) {//只出现一次的数字：按位异或
        int[] array = new int[]{1,2,3,1,2};
        System.out.println(find_Different(array));
    }
    public static void swap_Places(int[] array){//奇数位于偶数之前:双指针法
        int ps1 = 0;
        int ps2 = 0;
        while(ps2 != array.length){
            if(array[ps2] % 2 == 0){
                while(array[ps2] % 2 == 0){
                    if(ps2 == array.length - 1){
                        return;
                    }
                    ps2++;
                }
                //找到奇数了,交换
                int tmp = array[ps1];
                array[ps1] = array[ps2];
                array[ps2] = tmp;
                ps1++;
            }else{
                ps1++;
                ps2++;
            }
        }
    }
    public static void main2(String[] args) {
        int[] array = new int[]{2,4,6};
        System.out.println("交换前：");
        System.out.println(Arrays.toString(array));
        System.out.println("交换后：");
        swap_Places(array);
        System.out.println(Arrays.toString(array));
    }
    public static void transform(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }
    public static void main5(String[] args) {
        int[] array = new int[]{1,2,3,4,5,6};
        System.out.println("交换前：");
        for (int x:array) {
            System.out.print(x + " ");
        }
        transform(array);
        System.out.println();
        System.out.println("交换后：");
        for (int x:array) {
            System.out.print(x + " ");
        }
    }
}
